BX.namespace("BX.UI");if(typeof BX.UI.EntityUserFieldType==="undefined"){BX.UI.EntityUserFieldType={string:"string",integer:"integer",double:"double",boolean:"boolean",money:"money",date:"date",datetime:"datetime",enumeration:"enumeration",employee:"employee",crm:"crm",crmStatus:"crm_status",file:"file",url:"url"}}if(typeof BX.UI.EntityUserFieldManager==="undefined"){BX.UI.EntityUserFieldManager=function(){this._id="";this._settings={};this._entityId=0;this._fieldEntityId="";this._enableSelection=true;this._enableCreation=false;this._creationSignature="";this._creationPageUrl="";this._activeFields={};this._validationEnabled=true;this._validationResult=null;this._validationPromise=null;this._enableMandatoryControl=true;this._config=null;this._contextParams={}};BX.UI.EntityUserFieldManager.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._entityId=BX.prop.getInteger(this._settings,"entityId",0);this._fieldEntityId=BX.prop.getString(this._settings,"fieldEntityId","");this._enableSelection=BX.prop.getBoolean(this._settings,"enableSelection",true);this._enableCreation=BX.prop.getBoolean(this._settings,"enableCreation",false);this._creationSignature=BX.prop.getString(this._settings,"creationSignature","");this._creationPageUrl=BX.prop.getString(this._settings,"creationPageUrl","");this._enableMandatoryControl=BX.prop.getBoolean(this._settings,"enableMandatoryControl",true);this._contextParams=BX.prop.getObject(this._settings,"contextParams",{});if(typeof BX.UI.EntityEditorControlFactory!=="undefined"){BX.UI.EntityEditorControlFactory.registerFactoryMethod("userField",this.createEditorControl.bind(this))}else{BX.addCustomEvent("BX.UI.EntityEditorControlFactory:onInitialize",function(t,e){e.methods["userField"]=this.createEditorControl.bind(this)}.bind(this))}},isSelectionEnabled:function(){return this._enableSelection},isCreationEnabled:function(){return this._enableCreation},isModificationEnabled:function(){return this._enableSelection||this._enableCreation},isMandatoryControlEnabled:function(){return this._enableMandatoryControl},getDefaultFieldLabel:function(t){if(t==="string"){return BX.message("UI_ENTITY_EDITOR_UF_STRING_LABEL")}else if(t==="double"){return BX.message("UI_ENTITY_EDITOR_UF_DOUBLE_LABEL")}else if(t==="money"){return BX.message("UI_ENTITY_EDITOR_UF_MONEY_LABEL")}else if(t==="datetime"){return BX.message("UI_ENTITY_EDITOR_UF_DATETIME_LABEL")}else if(t==="enumeration"){return BX.message("UI_ENTITY_EDITOR_UF_ENUMERATION_LABEL")}else if(t==="file"){return BX.message("UI_ENTITY_EDITOR_UF_FILE_LABEL")}return BX.message("UI_ENTITY_EDITOR_UF_LABEL")},getFieldPrefix:function(){return BX.prop.getString(this._settings,"fieldPrefix","")},getAdditionalTypeList:function(){return BX.type.isArray(BX.UI.EntityUserFieldManager["additionalTypeList"])?BX.UI.EntityUserFieldManager["additionalTypeList"]:[]},getTypeInfos:function(){var t=[];t.push({name:"string",title:BX.message("UI_ENTITY_EDITOR_UF_STRING_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_STRING_LEGEND")});t.push({name:"enumeration",title:BX.message("UI_ENTITY_EDITOR_UF_ENUM_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_ENUM_LEGEND")});t.push({name:"datetime",title:BX.message("UI_ENTITY_EDITOR_UF_DATETIME_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_DATETIME_LEGEND")});t.push({name:"address",title:BX.message("UI_ENTITY_EDITOR_UF_ADDRESS_TITLE_2"),legend:BX.message("UI_ENTITY_EDITOR_UF_ADDRESS_LEGEND_2")});t.push({name:"url",title:BX.message("UI_ENTITY_EDITOR_UF_URL_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_URL_LEGEND")});t.push({name:"file",title:BX.message("UI_ENTITY_EDITOR_UF_FILE_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_FILE_LEGEND")});t.push({name:"money",title:BX.message("UI_ENTITY_EDITOR_UF_MONEY_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_MONEY_LEGEND")});t.push({name:"boolean",title:BX.message("UI_ENTITY_EDITOR_BOOLEAN_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_BOOLEAN_LEGEND")});t.push({name:"double",title:BX.message("UI_ENTITY_EDITOR_UF_DOUBLE_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_DOUBLE_LEGEND")});var e=this.getAdditionalTypeList();for(var i=0;i<e.length;i++){t.push({name:e[i].USER_TYPE_ID,title:e[i].TITLE,legend:e[i].LEGEND})}if(this._creationPageUrl){t.push({name:"custom",title:BX.message("UI_ENTITY_EDITOR_UF_CUSTOM_TITLE"),legend:BX.message("UI_ENTITY_EDITOR_UF_CUSTOM_LEGEND")})}var n=new BX.Event.BaseEvent({data:{types:t}});BX.Event.EventEmitter.emit("BX.UI.EntityUserFieldManager:getTypes",n);if(BX.Type.isArray(n.getData().types)){t=n.getData().types}return t},getCreationPageUrl:function(){return this._creationPageUrl},createEditorControl:function(t,e,i){if(t==="userField"){return BX.UI.EntityEditorUserField.create(e,i)}return null},createField:function(t,e){if(!this._enableCreation){return}var i=BX.prop.getString(t,"USER_TYPE_ID","");if(i===""){i=BX.UI.EntityUserFieldType.string}if(!BX.type.isNotEmptyString(t["EDIT_FORM_LABEL"])){t["EDIT_FORM_LABEL"]=this.getDefaultFieldLabel(i)}if(!BX.type.isNotEmptyString(t["LIST_COLUMN_LABEL"])){t["LIST_COLUMN_LABEL"]=t["EDIT_FORM_LABEL"]}if(!BX.type.isNotEmptyString(t["LIST_FILTER_LABEL"])){t["LIST_FILTER_LABEL"]=t["LIST_COLUMN_LABEL"]}this.addFieldLabel("EDIT_FORM_LABEL",t["EDIT_FORM_LABEL"],t);this.addFieldLabel("LIST_COLUMN_LABEL",t["LIST_COLUMN_LABEL"],t);this.addFieldLabel("LIST_FILTER_LABEL",t["LIST_FILTER_LABEL"],t);var n=new BX.Promise;var r=function(t){n.fulfill(t)};if(!BX.type.isNotEmptyString(t["FIELD"])){var o=this.getFieldPrefix();t["FIELD"]="UF_"+(o!==""?o+"_":"")+(new Date).getTime().toString()}t["ENTITY_ID"]=this._fieldEntityId;t["SIGNATURE"]=this._creationSignature;if(!BX.type.isNotEmptyString(t["MULTIPLE"])){t["MULTIPLE"]="N"}if(!BX.type.isNotEmptyString(t["MANDATORY"])){t["MANDATORY"]="N"}if(i===BX.UI.EntityUserFieldType.file){t["SHOW_FILTER"]="N";t["SHOW_IN_LIST"]="N"}else{if(i===BX.UI.EntityUserFieldType.employee||i===BX.UI.EntityUserFieldType.crm||i===BX.UI.EntityUserFieldType.crmStatus){t["SHOW_FILTER"]="I"}else{t["SHOW_FILTER"]="E"}t["SHOW_IN_LIST"]="Y"}if(i===BX.UI.EntityUserFieldType.enumeration){if(!t.hasOwnProperty("SETTINGS")){t["SETTINGS"]={}}}if(i===BX.UI.EntityUserFieldType.enumeration||i===BX.UI.EntityUserFieldType.crmStatus){t["SETTINGS"]["DISPLAY"]=t["SETTINGS"]["DISPLAY"]||"UI"}if(i===BX.UI.EntityUserFieldType.boolean){if(!t.hasOwnProperty("SETTINGS")){t["SETTINGS"]={}}t["SETTINGS"]["LABEL_CHECKBOX"]=t["EDIT_FORM_LABEL"]}if(i===BX.UI.EntityUserFieldType.double){if(!t.hasOwnProperty("SETTINGS")){t["SETTINGS"]={}}t["SETTINGS"]["PRECISION"]=2}t["CONTEXT_PARAMS"]=this._contextParams;if(e===BX.UI.EntityEditorMode.view){BX.Main.UF.ViewManager.add({FIELDS:[t]},r)}else{BX.Main.UF.EditManager.add({FIELDS:[t]},r)}BX.onCustomEvent(window,"BX.UI.EntityEditor:onUserFieldAdd",[this,t]);return n},updateField:function(t,e){t["ENTITY_ID"]=this._fieldEntityId;t["SIGNATURE"]=this._creationSignature;if(BX.type.isNotEmptyString(t["EDIT_FORM_LABEL"])){this.addFieldLabel("EDIT_FORM_LABEL",t["EDIT_FORM_LABEL"],t)}if(BX.type.isNotEmptyString(t["LIST_COLUMN_LABEL"])){this.addFieldLabel("LIST_COLUMN_LABEL",t["LIST_COLUMN_LABEL"],t)}if(BX.type.isNotEmptyString(t["LIST_FILTER_LABEL"])){this.addFieldLabel("LIST_FILTER_LABEL",t["LIST_FILTER_LABEL"],t)}var i=new BX.Promise;var n=function(t){i.fulfill(t)};BX.onCustomEvent(window,"BX.UI.EntityEditor:onBeforeUserFieldUpdate",[this,{fields:[t],onSuccess:n}]);if(t==="cancelUfUpdate"){return i}if(e===BX.UI.EntityEditorMode.view){BX.Main.UF.ViewManager.update({FIELDS:[t]},n)}else{BX.Main.UF.EditManager.update({FIELDS:[t]},n)}return i},resolveFieldName:function(t){return BX.prop.getString(t,"FIELD","")},addFieldLabel:function(t,e,i){var n=BX.prop.getArray(this._settings,"languages",[]);if(n.length===0){i[t]=e;return}i[t]={};for(var r=0,o=n.length;r<o;r++){var s=n[r];i[t][s["LID"]]=e}},prepareSchemeElementSettings:function(t){var e=BX.prop.getString(t,"FIELD","");if(e===""){return null}if(BX.prop.getString(t,"USER_TYPE_ID","")===""){t["USER_TYPE_ID"]="string"}if(BX.prop.getString(t,"ENTITY_ID","")===""){t["ENTITY_ID"]=this._fieldEntityId}if(BX.prop.getInteger(t,"ENTITY_VALUE_ID",0)<=0){t["ENTITY_VALUE_ID"]=this._entityId}return{name:e,originalTitle:BX.prop.getString(t,"EDIT_FORM_LABEL",e),title:BX.prop.getString(t,"EDIT_FORM_LABEL",e),type:"userField",required:BX.prop.getString(t,"MANDATORY","N")==="Y",data:{fieldInfo:t}}},createSchemeElement:function(t){return BX.UI.EntitySchemeElement.create(this.prepareSchemeElementSettings(t))},updateSchemeElement:function(t,e){var i=this.prepareSchemeElementSettings(e);i["title"]=t.getTitle();t.mergeSettings(i)},registerActiveField:function(t){var e=t.getName();this._activeFields[e]=t;BX.Main.UF.EditManager.registerField(e,t.getFieldInfo(),t.getFieldNode())},unregisterActiveField:function(t){var e=t.getName();if(this._activeFields.hasOwnProperty(e)){delete this._activeFields[e]}BX.Main.UF.EditManager.unRegisterField(e)},setValidationEnabled:function(t){this._validationEnabled=!!t},validate:function(t){var e=[];for(var i in this._activeFields){if(this._activeFields.hasOwnProperty(i)){e.push(i)}}if(this._validationEnabled&&e.length>0){this._validationResult=t;BX.Main.UF.EditManager.validate(e,BX.delegate(this.onValidationComplete,this))}else{window.setTimeout(BX.delegate((function(){if(this._validationPromise){this._validationPromise.fulfill();this._validationPromise=null}}),this),0)}this._validationPromise=new BX.Promise;return this._validationPromise},onValidationComplete:function(t){var e;for(e in this._activeFields){if(this._activeFields.hasOwnProperty(e)){this._activeFields[e].clearError()}}for(e in t){if(!t.hasOwnProperty(e)){continue}if(this._activeFields.hasOwnProperty(e)){var i=this._activeFields[e];i.showError(t[e]);this._validationResult.addError(BX.UI.EntityValidationError.create({field:i}))}}if(this._validationPromise){this._validationPromise.fulfill()}this._validationResult=null;this._validationPromise=null}};BX.UI.EntityUserFieldManager.items={};BX.UI.EntityUserFieldManager.create=function(t,e){var i=new BX.UI.EntityUserFieldManager;i.initialize(t,e);this.items[t]=i;return i};BX.UI.EntityUserFieldManager.getById=function(t){return this.items.hasOwnProperty(t)?this.items[t]:null}}if(typeof BX.UI.EntityUserFieldLayoutLoader==="undefined"){BX.UI.EntityUserFieldLayoutLoader=function(){this._id="";this._settings={};this._mode=BX.UI.EntityEditorMode.view;this._enableBatchMode=true;this._owner=null;this._items=[]};BX.UI.EntityUserFieldLayoutLoader.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._mode=BX.prop.getInteger(this._settings,"mode",BX.UI.EntityEditorMode.view);this._enableBatchMode=BX.prop.getBoolean(this._settings,"enableBatchMode",true);this._owner=BX.prop.get(this._settings,"owner",null)},getId:function(){return this._id},getOwner:function(){return this._owner},addItem:function(t){this._items.push(t)},run:function(){if(!this._enableBatchMode){this.startRequest()}},runBatch:function(){if(this._enableBatchMode){this.startRequest()}},startRequest:function(){if(this._items.length===0){return}var t=[];for(var e=0,i=this._items.length;e<i;e++){if(BX.prop.getString(this._items[e],"name","")!==""){t.push(BX.prop.getObject(this._items[e],"field",{}))}}if(t.length===0){return}var n={FIELDS:t,FORM:this._id,CONTEXT:"UI_EDITOR"};if(this._mode===BX.UI.EntityEditorMode.view){BX.Main.UF.Manager.getView(n,BX.delegate(this.onRequestComplete,this))}else{BX.Main.UF.Manager.getEdit(n,BX.delegate(this.onRequestComplete,this))}},onRequestComplete:function(t){for(var e=0,i=this._items.length;e<i;e++){var n=this._items[e];var r=BX.prop.getString(n,"name","");var o=BX.prop.getFunction(n,"callback",null);if(r!==""&&o!==null){o(BX.prop.getObject(t,r,{}))}}}};BX.UI.EntityUserFieldLayoutLoader.create=function(t,e){var i=new BX.UI.EntityUserFieldLayoutLoader;i.initialize(t,e);return i}}if(typeof BX.UI.EntityEditorUserField==="undefined"){BX.UI.EntityEditorUserField=function(){BX.UI.EntityEditorUserField.superclass.constructor.apply(this);this._innerWrapper=null;this._isLoaded=false;this._focusOnLoad=false;this.isClickBinded=false};BX.extend(BX.UI.EntityEditorUserField,BX.UI.EntityEditorField);BX.UI.EntityEditorUserField.prototype.doInitialize=function(){BX.UI.EntityEditorUserField.superclass.doInitialize.apply(this);this._manager=this._editor.getUserFieldManager()};BX.UI.EntityEditorUserField.prototype.getModeSwitchType=function(t){var e=BX.UI.EntityEditorModeSwitchType.common;if(t===BX.UI.EntityEditorMode.edit){e|=BX.UI.EntityEditorModeSwitchType.button|BX.UI.EntityEditorModeSwitchType.content}return e};BX.UI.EntityEditorUserField.prototype.getContentWrapper=function(){return this._innerWrapper};BX.UI.EntityEditorUserField.prototype.getFieldInfo=function(){return this._schemeElement.getDataParam("fieldInfo",{})};BX.UI.EntityEditorUserField.prototype.getFieldType=function(){return BX.prop.getString(this.getFieldInfo(),"USER_TYPE_ID","")};BX.UI.EntityEditorUserField.prototype.getFieldSettings=function(){return BX.prop.getObject(this.getFieldInfo(),"SETTINGS",{})};BX.UI.EntityEditorUserField.prototype.isMultiple=function(){return BX.prop.getString(this.getFieldInfo(),"MULTIPLE","N")==="Y"};BX.UI.EntityEditorUserField.prototype.getEntityValueId=function(){return BX.prop.getString(this.getFieldInfo(),"ENTITY_VALUE_ID","")};BX.UI.EntityEditorUserField.prototype.getFieldValue=function(){var t=this.getValue();var e=BX.prop.getArray(t,"VALUE",null);if(e===null){e=BX.prop.getString(t,"VALUE","")}return e};BX.UI.EntityEditorUserField.prototype.getFieldSignature=function(){return BX.prop.getString(this.getValue(),"SIGNATURE","")};BX.UI.EntityEditorUserField.prototype.isTitleEnabled=function(){var t=this.getFieldInfo();var e=BX.prop.getString(t,"USER_TYPE_ID","");if(e!=="boolean"){return true}return BX.prop.getString(BX.prop.getObject(t,"SETTINGS",{}),"DISPLAY","")!=="CHECKBOX"};BX.UI.EntityEditorUserField.prototype.getFieldNode=function(){return this._innerWrapper};BX.UI.EntityEditorUserField.prototype.checkIfNotEmpty=function(t){if(BX.prop.getBoolean(t,"IS_EMPTY",false)){return false}var e;if(this.getFieldType()===BX.UI.EntityUserFieldType.boolean){e=BX.prop.getString(t,"VALUE","");return e!==""}e=BX.prop.getArray(t,"VALUE",null);if(e===null){e=BX.prop.getString(t,"VALUE","")}return BX.type.isArray(e)?e.length>0:e!==""};BX.UI.EntityEditorUserField.prototype.getValue=function(t){if(t===undefined){t=null}if(!this._model){return t}return this._model.getField(this.getName(),t)};BX.UI.EntityEditorUserField.prototype.hasContentToDisplay=function(){if(this._mode===BX.UI.EntityEditorMode.edit){return true}if(this.checkOptionFlag(BX.UI.EntityEditorControlOptions.showAlways)&&this.getFieldType().indexOf("rest_")===0){return true}return this.checkIfNotEmpty(this.getValue())};BX.UI.EntityEditorUserField.prototype.layout=function(t){if(this._hasLayout){return}var e=this.getName();var i=this.getTitle();var n=this.getFieldInfo();var r=this.getValue();var o=BX.prop.getString(r,"SIGNATURE","");this.ensureWrapperCreated();this.adjustWrapper();if(!this.isNeedToDisplay()){this.registerLayout(t);this._hasLayout=true;return}var s=this.getFieldType();if(s===BX.UI.EntityUserFieldType.string){BX.addClass(this._wrapper,"ui-entity-editor-content-block-field-custom-text")}else if(s===BX.UI.EntityUserFieldType.integer||s===BX.UI.EntityUserFieldType.double){BX.addClass(this._wrapper,"ui-entity-editor-content-block-field-custom-number")}else if(s===BX.UI.EntityUserFieldType.money){BX.addClass(this._wrapper,"ui-entity-editor-content-block-field-custom-money")}else if(s===BX.UI.EntityUserFieldType.date||s===BX.UI.EntityUserFieldType.datetime){BX.addClass(this._wrapper,"ui-entity-editor-content-block-field-custom-date")}else if(s===BX.UI.EntityUserFieldType.boolean){BX.addClass(this._wrapper,"ui-entity-editor-field-custom-checkbox")}else if(s===BX.UI.EntityUserFieldType.enumeration){BX.addClass(this._wrapper,this.isMultiple()?"ui-entity-editor-content-block-field-custom-multiselect":"ui-entity-editor-content-block-field-custom-select")}else if(s===BX.UI.EntityUserFieldType.file){BX.addClass(this._wrapper,"ui-entity-editor-content-block-field-custom-file")}else if(s===BX.UI.EntityUserFieldType.url){BX.addClass(this._wrapper,"ui-entity-editor-content-block-field-custom-link")}this._innerWrapper=null;if(this.isDragEnabled()){this._wrapper.appendChild(this.createDragButton())}if(this._mode===BX.UI.EntityEditorMode.edit){if(this.isTitleEnabled()){this._wrapper.appendChild(this.createTitleNode(i))}this._innerWrapper=BX.create("div",{props:{className:"ui-entity-editor-content-block"}})}else{this._wrapper.appendChild(this.createTitleNode(i));this._innerWrapper=BX.create("div",{props:{className:"ui-entity-editor-content-block"}})}this._wrapper.appendChild(this._innerWrapper);if(this.isContextMenuEnabled()){this._wrapper.appendChild(this.createContextMenuButton())}if(this.isDragEnabled()){this.initializeDragDropAbilities()}this.registerLayout(t);if(this.hasContentToDisplay()){var a=BX.prop.getString(t,"html","");if(a===""){a=BX.prop.getString(BX.prop.getObject(r,"HTML",{}),BX.UI.EntityEditorMode.getName(this._mode).toUpperCase(),"")}if(a!==""){this.setupContentHtml(a);this._hasLayout=true}else{this._isLoaded=false;var l=null;if(!this.isInSingleEditMode()){l=BX.prop.get(t,"userFieldLoader",null)}if(!l){l=BX.UI.EntityUserFieldLayoutLoader.create(this._id,{mode:this._mode,enableBatchMode:false})}var d=BX.clone(n);d["SIGNATURE"]=o;if(s===BX.UI.EntityUserFieldType.file&&BX.type.isObject(d["ADDITIONAL"])){var u=BX.prop.getString(BX.prop.getObject(r,"EXTRAS",{}),"OWNER_TOKEN","");if(u!==""){d["ADDITIONAL"]["URL_TEMPLATE"]+="&owner_token="+encodeURIComponent(u)}}if(this.checkIfNotEmpty(r)){var p=BX.prop.getArray(r,"VALUE",null);if(p===null){p=BX.prop.getString(r,"VALUE","")}d["VALUE"]=p}this.adjustFieldParams(d,true);l.addItem({name:e,field:d,callback:BX.delegate(this.onLayoutLoaded,this)});l.run()}}else{this._innerWrapper.appendChild(document.createTextNode(BX.message("UI_ENTITY_EDITOR_FIELD_EMPTY")));this._hasLayout=true}};BX.UI.EntityEditorUserField.prototype.doRegisterLayout=function(){};BX.UI.EntityEditorUserField.prototype.adjustFieldParams=function(t,e){var i=this.getFieldType();if(i===BX.UI.EntityUserFieldType.boolean){if(!BX.type.isPlainObject(t["SETTINGS"])){t["SETTINGS"]={}}t["SETTINGS"]["LABEL_CHECKBOX"]=this.getTitle()}if(e&&typeof t["VALUE"]!=="undefined"&&this._mode===BX.UI.EntityEditorMode.edit&&BX.prop.getInteger(t,"ENTITY_VALUE_ID")<=0){t["ENTITY_VALUE_ID"]=1}};BX.UI.EntityEditorUserField.prototype.validate=function(){return true};BX.UI.EntityEditorUserField.prototype.save=function(){};BX.UI.EntityEditorUserField.prototype.focus=function(){if(this._mode!==BX.UI.EntityEditorMode.edit){return}if(this._isLoaded){this.doFocus()}else{this._focusOnLoad=true}};BX.UI.EntityEditorUserField.prototype.doFocus=function(){BX.Main.UF.Factory.focus(this.getName())};BX.UI.EntityEditorUserField.prototype.setupContentHtml=function(t){if(this._innerWrapper){BX.html(this._innerWrapper,t).then(function(){this.onLayoutSuccess();this._isLoaded=true;if(this._focusOnLoad===true){this.doFocus();this._focusOnLoad=false}}.bind(this))}};BX.UI.EntityEditorUserField.prototype.doSetActive=function(){if(!this._isActive){this._manager.unregisterActiveField(this)}};BX.UI.EntityEditorUserField.prototype.rollback=function(){this._manager.unregisterActiveField(this)};BX.UI.EntityEditorUserField.prototype.onLayoutSuccess=function(){if(this._isActive){this._manager.registerActiveField(this)}window.setTimeout(function(){BX.bindDelegate(this._innerWrapper,"bxchange",{tag:["input","select","textarea"]},this._changeHandler)}.bind(this),200);var t=this.getFieldType();if(t===BX.UI.EntityUserFieldType.employee){var e=this._innerWrapper.querySelector(".feed-add-destination-link");if(e&&this.isClickBinded){BX.bind(e,"click",BX.delegate(this.onEmployeeSelectorOpen,this));this.isClickBinded=true}}if(t===BX.UI.EntityUserFieldType.boolean){if(this._mode===BX.UI.EntityEditorMode.edit&&!this.checkIfNotEmpty(this.getValue())){this.markAsChanged()}}if(!this._hasLayout){this._hasLayout=true}this.addExternalEventsHandlers()};BX.UI.EntityEditorUserField.prototype.doClearLayout=function(t){this._innerWrapper=null;this.removeExternalEventsHandlers()};BX.UI.EntityEditorUserField.prototype.addExternalEventsHandlers=function(){this.removeExternalEventsHandlers();BX.addCustomEvent(window,"onUIEntityEditorUserFieldExternalChanged",BX.proxy(this.userFieldExternalChangedHandler,this));BX.addCustomEvent(window,"onUIEntityEditorUserFieldSetValidator",BX.proxy(this.userFieldSetValidatorHandler,this))};BX.UI.EntityEditorUserField.prototype.removeExternalEventsHandlers=function(){BX.removeCustomEvent(window,"onUIEntityEditorUserFieldExternalChanged",BX.proxy(this.userFieldExternalChangedHandler,this));BX.removeCustomEvent(window,"onUIEntityEditorUserFieldSetValidator",BX.proxy(this.userFieldSetValidatorHandler,this))};BX.UI.EntityEditorUserField.prototype.userFieldExternalChangedHandler=function(t){if(t==this._id&&BX.type.isFunction(this._changeHandler)){this._changeHandler()}};BX.UI.EntityEditorUserField.prototype.release=function(){this.removeExternalEventsHandlers()};BX.UI.EntityEditorUserField.prototype.userFieldSetValidatorHandler=function(t,e){if(t==this._id&&BX.type.isFunction(e)){this.validate=e}};BX.UI.EntityEditorUserField.prototype.onLayoutLoaded=function(t){var e=BX.prop.getString(t,"HTML","");if(e!==""){this.setupContentHtml(e);this._hasLayout=true;this.raiseLayoutEvent()}};BX.UI.EntityEditorUserField.prototype.onEmployeeSelectorOpen=function(t){var e=BX.getEventTarget(t);if(!e){return}var i=e.id.match(/^add_user_([a-z_0-9-]+)/i);if(BX.type.isArray(i)&&i.length>1){var n=BX.Intranet.UserFieldEmployee.instance(i[1]);if(n){BX.addCustomEvent(n,"onUpdateValue",this._changeHandler)}}};BX.UI.EntityEditorUserField.create=function(t,e){var i=new BX.UI.EntityEditorUserField;i.initialize(t,e);return i}}if(typeof BX.UI.EntityEditorUserFieldListItem==="undefined"){BX.UI.EntityEditorUserFieldListItem=function(){BX.UI.EntityEditorUserFieldListItem.superclass.constructor.apply(this)};BX.extend(BX.UI.EntityEditorUserFieldListItem,BX.UI.EntityEditorFieldConfiguratorEnumItem);BX.UI.EntityEditorUserFieldListItem.prototype.prepareData=function(){var t=this._labelInput?BX.util.trim(this._labelInput.value):"";if(t===""){return null}var e={VALUE:t};var i=BX.prop.getInteger(this._data,"ID",0);if(i>0){e["ID"]=i}var n=BX.prop.getString(this._data,"XML_ID","");if(i>0){e["XML_ID"]=n}return e};BX.UI.EntityEditorUserFieldListItem.create=function(t,e){var i=new BX.UI.EntityEditorUserFieldListItem;i.initialize(t,e);return i}}if(typeof BX.UI.UserFieldTypeMenu==="undefined"){BX.UI.UserFieldTypeMenu=function(){this._id=null;this._settings={};this._items=null;this._isOpened=false;this._wrapper=null;this._innerWrapper=null;this._topScrollButton=null;this._bottomScrollButton=null;this._bottomButtonMouseOverHandler=BX.delegate(this.onBottomButtonMouseOver,this);this._bottomButtonMouseOutHandler=BX.delegate(this.onBottomButtonMouseOut,this);this._topButtonMouseOverHandler=BX.delegate(this.onTopButtonMouseOver,this);this._topButtonMouseOutHandler=BX.delegate(this.onTopButtonMouseOut,this);this._scrollHandler=BX.throttle(this.onScroll,100,this);this._enableScrollToBottom=false;this._enableScrollToTop=false;this._popup=null};BX.UI.UserFieldTypeMenu.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._items=[];var i=BX.prop.getArray(e,"items");for(var n=0,r=i.length;n<r;n++){var o=i[n];o["menu"]=this;this._items.push(BX.UI.UserFieldTypeMenuItem.create(BX.prop.getString(o,"value"),o))}},getId:function(){return this._id},isOpened:function(){return this._isOpened},open:function(t){if(this._isOpened){return}this._popup=new BX.PopupWindow(this._id,t,{autoHide:true,draggable:false,offsetLeft:0,offsetTop:0,noAllPaddings:true,bindOptions:{forceBindPosition:true},closeByEsc:true,events:{onPopupShow:BX.delegate(this.onPopupShow,this),onPopupClose:BX.delegate(this.onPopupClose,this),onPopupDestroy:BX.delegate(this.onPopupDestroy,this)},content:this.prepareContent()});this._popup.show()},close:function(){if(!this._isOpened){return}if(this._popup){this._popup.close()}},prepareContent:function(){this._wrapper=BX.create("div",{props:{className:"ui-entity-editor-popup-create-field-popup"}});var t='<svg xmlns="http://www.w3.org/2000/svg" width="42" height="13" viewBox="0 0 42 13">\n'+'  <polyline fill="none" stroke="#CACDD1" stroke-width="2" points="274 98 284 78.614 274 59" transform="rotate(90 186 -86.5)" stroke-linecap="round" stroke-linejoin="round"/>\n'+"</svg>\n";this._topScrollButton=BX.create("div",{props:{className:"ui-entity-editor-popup-create-scroll-control-top"},html:t});this._wrapper.appendChild(this._topScrollButton);this._bottomScrollButton=BX.create("div",{props:{className:"ui-entity-editor-popup-create-scroll-control-bottom"},html:t});this._wrapper.appendChild(this._bottomScrollButton);this._innerWrapper=BX.create("div",{props:{className:"ui-entity-editor-popup-create-field-list"}});this._wrapper.appendChild(this._innerWrapper);for(var e=0,i=this._items.length;e<i;e++){this._innerWrapper.appendChild(this._items[e].prepareContent())}return this._wrapper},adjust:function(){var t=this._innerWrapper.offsetHeight;var e=this._innerWrapper.scrollTop;var i=this._innerWrapper.scrollHeight;if(e===0){BX.addClass(this._topScrollButton,"control-hide")}else{BX.removeClass(this._topScrollButton,"control-hide")}if(e+t===i){BX.addClass(this._bottomScrollButton,"control-hide")}else{BX.removeClass(this._bottomScrollButton,"control-hide")}},onItemSelect:function(t){var e=t.getCallback();if(!BX.type.isFunction(e)){e=BX.prop.getFunction(this._settings,"callback",null)}if(e){e(this,t)}},onPopupShow:function(){this._isOpened=true;BX.bind(this._bottomScrollButton,"mouseover",this._bottomButtonMouseOverHandler);BX.bind(this._bottomScrollButton,"mouseout",this._bottomButtonMouseOutHandler);BX.bind(this._topScrollButton,"mouseover",this._topButtonMouseOverHandler);BX.bind(this._topScrollButton,"mouseout",this._topButtonMouseOutHandler);BX.bind(this._innerWrapper,"scroll",this._scrollHandler);window.setTimeout(this.adjust.bind(this),100)},onPopupClose:function(){if(this._popup){this._popup.destroy()}},onPopupDestroy:function(){this._isOpened=false;BX.unbind(this._bottomScrollButton,"mouseover",this._bottomButtonMouseOverHandler);BX.unbind(this._bottomScrollButton,"mouseout",this._bottomButtonMouseOutHandler);BX.unbind(this._topScrollButton,"mouseover",this._topButtonMouseOverHandler);BX.unbind(this._topScrollButton,"mouseout",this._topButtonMouseOutHandler);BX.unbind(this._innerWrapper,"scroll",this._scrollHandler);this._wrapper=null;this._innerWrapper=null;this._topScrollButton=null;this._bottomScrollButton=null;this._popup=null},onBottomButtonMouseOver:function(t){if(this._enableScrollToBottom){return}this._enableScrollToBottom=true;this._enableScrollToTop=false;(function t(){if(!this._enableScrollToBottom){return}var e=this._innerWrapper;if(e.scrollTop+e.offsetHeight!==e.scrollHeight){e.scrollTop+=3}if(e.scrollTop+e.offsetHeight===e.scrollHeight){this._enableScrollToBottom=false}else{window.setTimeout(t.bind(this),20)}}).bind(this)()},onBottomButtonMouseOut:function(){this._enableScrollToBottom=false},onTopButtonMouseOver:function(t){if(this._enableScrollToTop){return}this._enableScrollToBottom=false;this._enableScrollToTop=true;(function t(){if(!this._enableScrollToTop){return}var e=this._innerWrapper;if(e.scrollTop>0){e.scrollTop-=3}if(e.scrollTop===0){this._enableScrollToTop=false}else{window.setTimeout(t.bind(this),20)}}).bind(this)()},onTopButtonMouseOut:function(){this._enableScrollToTop=false},onScroll:function(t){this.adjust()}};BX.UI.UserFieldTypeMenu.create=function(t,e){var i=new BX.UI.UserFieldTypeMenu;i.initialize(t,e);return i}}if(typeof BX.UI.UserFieldTypeMenuItem==="undefined"){BX.UI.UserFieldTypeMenuItem=function(){this._id="";this._settings=null;this._menu="";this._value="";this._text="";this._legend="";this._callback=null};BX.UI.UserFieldTypeMenuItem.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._menu=BX.prop.get(e,"menu");this._value=BX.prop.getString(e,"value");this._text=BX.prop.getString(e,"text");this._legend=BX.prop.getString(e,"legend");this._callback=BX.prop.getFunction(e,"callback",null)},getId:function(){return this._id},getValue:function(){return this._value},getText:function(){return this._text},getLegend:function(){return this._legend},getCallback:function(){return this._callback},prepareContent:function(){var t=BX.create("span",{props:{className:"ui-entity-editor-popup-create-field-item"},events:{click:BX.delegate(this.onClick,this)}});t.appendChild(BX.create("span",{props:{className:"ui-entity-editor-popup-create-field-item-title"},text:this._text}));t.appendChild(BX.create("span",{props:{className:"ui-entity-editor-popup-create-field-item-desc"},text:this._legend}));return t},onClick:function(t){this._menu.onItemSelect(this)}};BX.UI.UserFieldTypeMenuItem.create=function(t,e){var i=new BX.UI.UserFieldTypeMenuItem;i.initialize(t,e);return i}}if(typeof BX.UI.EntityEditorUserFieldConfigurator==="undefined"){BX.UI.EntityEditorUserFieldConfigurator=function(){BX.UI.EntityEditorUserFieldConfigurator.superclass.constructor.apply(this);this._field=null;this._typeId="";this._isLocked=false;this._labelInput=null;this._saveButton=null;this._cancelButton=null;this._isTimeEnabledCheckBox=null;this._isRequiredCheckBox=null;this._isMultipleCheckBox=null;this._showAlwaysCheckBox=null;this._optionWrapper=null;this._enumConfigurator=null;this._enableMandatoryControl=true;this._mandatoryConfigurator=null};BX.extend(BX.UI.EntityEditorUserFieldConfigurator,BX.UI.EntityEditorFieldConfigurator);BX.UI.EntityEditorUserFieldConfigurator.prototype.checkField=function(){if(this._field&&!(this._field instanceof BX.UI.EntityEditorUserField)){throw"EntityEditorUserFieldConfigurator. The 'field' param must be EntityEditorUserField."}};BX.UI.EntityEditorUserFieldConfigurator.prototype.getDefaultFieldLabel=function(){var t=this._editor.getUserFieldManager();return t.getDefaultFieldLabel(this._typeId)};BX.UI.EntityEditorUserFieldConfigurator.prototype.getInputTitle=function(){var t=this._editor.getUserFieldManager();return this._field?this._field.getTitle():t.getDefaultFieldLabel(this._typeId)};BX.UI.EntityEditorUserFieldConfigurator.prototype.getInputContainer=function(){var t=BX.message("UI_ENTITY_EDITOR_FIELD_TITLE");this._labelInput=BX.create("input",{attrs:{className:"ui-ctl-element",type:"text",value:this.getInputTitle()}});return BX.create("div",{props:{className:"ui-entity-editor-content-block"},children:[BX.create("div",{props:{className:"ui-entity-editor-block-title"},children:[BX.create("span",{attrs:{className:"ui-entity-editor-block-title-text"},text:t})]}),BX.create("div",{props:{className:"ui-entity-editor-content-block"},children:[BX.create("div",{props:{className:"ui-ctl ui-ctl-textbox ui-ctl-w100"},children:[this._labelInput]})]})]})};BX.UI.EntityEditorUserFieldConfigurator.prototype.layoutInnerConfigurator=function(t,e,i){if(BX.Type.isPlainObject(t)&&BX.Type.isArray(e)&&this._enumConfigurator===null){var n=[];for(var r=0;r<e.length;r++){n.push({ID:e[r]["VALUE"],VALUE:e[r]["NAME"],XML_ID:""})}var o=this._settings.field._schemeElement._data.fieldInfo.SETTINGS;var s=false;if(this._typeId===BX.UI.EntityUserFieldType.enumeration){s=true}this._enumConfigurator=BX.UI.EntityEditorEnumConfigurator.create({enumInfo:{enumItems:n,innerConfig:t},wrapper:this._wrapper,nextNode:BX.Type.isDomNode(i)?i:null,display:o?o.DISPLAY:null,showDisplaySettings:s});this._enumConfigurator.layout()}};BX.UI.EntityEditorUserFieldConfigurator.prototype.layoutInternal=function(){this._wrapper.appendChild(this.getInputContainer());if(this._typeId===BX.UI.EntityUserFieldType.enumeration&&(!this._field||this._field.getEditor().canChangeCommonConfiguration())){if(this._enumConfigurator===null){var t=this._field?this._field.getFieldInfo():{};var e=BX.prop.getArray(t,"ENUM",[]);var i=BX.prop.getObject(t,"SETTINGS",null);this._enumConfigurator=BX.UI.EntityEditorUserFieldEnumConfigurator.create({enumInfo:{enumItems:e},wrapper:this._wrapper,display:i?i.DISPLAY:null,showDisplaySettings:true});this._enumConfigurator.layout()}}var n=this.getOptionContainer();this._wrapper.appendChild(n);this._wrapper.appendChild(BX.create("hr",{props:{className:"ui-entity-editor-line"}}));this._wrapper.appendChild(this.getButtonContainer());if(this._typeId===BX.UI.EntityUserFieldType.crmStatus){var r=this._field.getInnerConfig();if(BX.Type.isPlainObject(r)){BX.ajax.runAction("crm.status.getItems",{data:{configData:{innerConfig:r}}}).then(function(t){if(BX.Type.isObject(t)&&t.hasOwnProperty("status")&&t.status==="success"&&t.hasOwnProperty("data")&&BX.Type.isArray(t["data"])){var e=t["data"];var i=[];for(var o=0;o<e.length;o++){i.push({NAME:e[o]["VALUE"],VALUE:e[o]["ID"]})}this.layoutInnerConfigurator(r,i,n)}else{console.error("Invalid server response.")}}.bind(this),function(t){if(BX.Type.isObject(t)&&t.hasOwnProperty("status")&&t["status"]==="error"&&t.hasOwnProperty("errors")&&BX.Type.isArray(t["errors"])&&t["errors"].length>0&&BX.Type.isPlainObject(t["errors"][0])&&t["errors"][0].hasOwnProperty("message")&&BX.Type.isString(t["errors"][0]["message"])){console.error(t["errors"][0]["message"])}else{console.error("Invalid server response.")}}.bind(this))}}};BX.UI.EntityEditorUserFieldConfigurator.prototype.getOptionContainer=function(){var t=this._field===null;this._optionWrapper=BX.create("div",{props:{className:"ui-entity-editor-content-block"}});this._wrapper.appendChild(BX.create("div",{props:{className:"ui-entity-editor-content-block ui-entity-editor-content-block-checkbox"},children:[this._optionWrapper]}));if(t&&(this._typeId==="datetime"||this._typeId==="date")){this._isTimeEnabledCheckBox=this.createOption({caption:BX.message("UI_ENTITY_EDITOR_UF_ENABLE_TIME")})}if(this._typeId!=="boolean"){if(this.getEditor().canChangeCommonConfiguration()&&this._enableMandatoryControl){if(this._mandatoryConfigurator){this._isRequiredCheckBox=this.createOption({caption:this._mandatoryConfigurator.getTitle()+":",containerSettings:{props:{className:"ui-entity-new-field-addiction-flex-row"}},elements:this._mandatoryConfigurator.getButton().prepareLayout()});this._isRequiredCheckBox.checked=this._field&&this._field.isRequired()||this._mandatoryConfigurator.isCustomized();this._mandatoryConfigurator.setSwitchCheckBox(this._isRequiredCheckBox);this._mandatoryConfigurator.setLabel(this._isRequiredCheckBox.nextSibling);this._mandatoryConfigurator.setEnabled(this._isRequiredCheckBox.checked);this._mandatoryConfigurator.adjust()}else{this._isRequiredCheckBox=this.createOption({caption:BX.message("UI_ENTITY_EDITOR_UF_REQUIRED_FIELD")});this._isRequiredCheckBox.checked=this._field&&this._field.isRequired()}}if(t){this._isMultipleCheckBox=this.createOption({caption:BX.message("UI_ENTITY_EDITOR_UF_MULTIPLE_FIELD")})}}this._showAlwaysCheckBox=this.createOption({caption:BX.message("UI_ENTITY_EDITOR_SHOW_ALWAYS"),helpCode:"9627471"});this._showAlwaysCheckBox.checked=t?BX.prop.getBoolean(this._settings,"showAlways",true):this._field.checkOptionFlag(BX.UI.EntityEditorControlOptions.showAlways);return this._optionWrapper};BX.UI.EntityEditorUserFieldConfigurator.prototype.prepareSaveParams=function(t){var e=BX.UI.EntityEditorUserFieldConfigurator.superclass.prepareSaveParams.apply(this,arguments);if((this._typeId===BX.UI.EntityUserFieldType.enumeration||this._typeId===BX.UI.EntityUserFieldType.crmStatus)&&this._enumConfigurator){e["innerConfig"]=this._field?this._field.getInnerConfig():{};e["enumeration"]=this._enumConfigurator.prepareSaveParams();e["display"]=this._enumConfigurator.getDisplaySelectValue()}if(this._field){if(this._isMultipleCheckBox){e["multiple"]=this._isMultipleCheckBox.checked}}else{if(this._typeId==="boolean"){e["multiple"]=false}else if(this._isMultipleCheckBox){e["multiple"]=this._isMultipleCheckBox.checked}if(this._typeId==="datetime"){e["enableTime"]=this._isTimeEnabledCheckBox.checked}}return e};BX.UI.EntityEditorUserFieldConfigurator.prototype.getIsRequiredCheckBox=function(){var t=null;if(this._typeId!=="boolean"){if(this._enableMandatoryControl){if(this._mandatoryConfigurator){t=this.createOption({caption:this._mandatoryConfigurator.getTitle()+":",containerSettings:{style:{alignItems:"center"}},elements:this._mandatoryConfigurator.getButton().prepareLayout()});t.checked=this._field&&this._field.isRequired()||this._mandatoryConfigurator.isCustomized();this._mandatoryConfigurator.setSwitchCheckBox(t);this._mandatoryConfigurator.setLabel(t.nextSibling);this._mandatoryConfigurator.setEnabled(t.checked);this._mandatoryConfigurator.adjust()}else{t=this.createOption({caption:BX.message("UI_ENTITY_EDITOR_UF_REQUIRED_FIELD")});t.checked=this._field&&this._field.isRequired()}}}return t};BX.UI.EntityEditorUserFieldConfigurator.create=function(t,e){var i=new BX.UI.EntityEditorUserFieldConfigurator;i.initialize(t,e);return i};BX.onCustomEvent(window,"BX.UI.EntityEditorUserFieldConfigurator:onDefine")}if(typeof BX.UI.EntityEditorUserFieldEnumConfigurator==="undefined"){BX.UI.EntityEditorUserFieldEnumConfigurator=function(){BX.UI.EntityEditorUserFieldEnumConfigurator.superclass.constructor.apply(this)};BX.extend(BX.UI.EntityEditorUserFieldEnumConfigurator,BX.UI.EntityEditorEnumConfigurator);BX.UI.EntityEditorUserFieldEnumConfigurator.prototype.createEnumerationItem=function(t){var e=BX.UI.EntityEditorUserFieldListItem.create("",{configurator:this,container:this._enumItemContainer,data:t});this._enumItems.push(e);e.layout();return e};BX.UI.EntityEditorUserFieldEnumConfigurator.create=function(t){var e=new BX.UI.EntityEditorUserFieldEnumConfigurator;e.initialize(t);return e}}
//# sourceMappingURL=user-field.map.js